package edu.ped.android.view;
import edu.ped.android.utils.TagsMatrice;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;


public class MatriceView extends View {


	public boolean draw=false;
	TagsMatrice m_matrice;

	public MatriceView(Context context, TagsMatrice matrice){
		this(context);
		m_matrice = matrice;
	}

	public MatriceView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);

	}

	public MatriceView(Context context, AttributeSet attrs) {
		super(context, attrs);
		draw=true;
	}

	public MatriceView(Context context) {
		super(context);
	}

	public void setMatrice(TagsMatrice matrice){
		m_matrice=matrice;
	}

	@Override
	protected void onDraw(Canvas canvas) {
		Paint paint = new Paint();
		if(m_matrice!=null && draw ){
			int tailleX=  getWidth() /  m_matrice.getHorizontal_size();
			int tailleY=  getHeight() /   m_matrice.getVertical_size();
			int taille = Math.min(tailleX,tailleY);
			for(int i=0;i<m_matrice.getHorizontal_size();i++)
				for(int j=0;j<m_matrice.getVertical_size();j++){
					if(m_matrice.getTag(i, j)!=null && m_matrice.getTag(i, j).getValeur() != null){
						paint.setColor((Integer)m_matrice.getTag(i, j).getValeur());
						canvas.drawRect(new RectF(j*taille	, i*taille	, (j+1)*taille, (i+1)*taille ), paint);
					}
				}
		}
	}
}
